﻿<Common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Antares.VIEWs.SearchContractPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:common="using:Antares.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Converters="using:Antares.Converters"
    xmlns:Common="using:AntaresShell.Common" xmlns:local="using:Antares.VIEWs" mc:Ignorable="d"
    d:ExtensionType="Search">
    <Common:LayoutAwarePage.Transitions>
        <TransitionCollection>
            <EntranceThemeTransition FromHorizontalOffset="300"/>
        </TransitionCollection>
    </Common:LayoutAwarePage.Transitions>
    <Page.Resources>
        <CollectionViewSource x:Name="resultsViewSource" Source="{Binding Results}"/>
        <CollectionViewSource x:Name="filtersViewSource" Source="{Binding Filters}"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <x:String x:Key="AppName">eSec</x:String>
        <DataTemplate x:Key="TaskTemplate">
            <local:ProjectTaskItem/>
        </DataTemplate>

        <DataTemplate x:Key="TaskTemplate1">
            <Grid x:Name="ItemGrid" Height="90" Width="292" Tapped="UIElement_OnTapped">
                <Grid.Resources>
                    <Style x:Key="TxtProjectStyle" TargetType="TextBlock">
                        <Setter Property="FontFamily" Value="Segoe UI"/>
                        <Setter Property="FontWeight" Value="SemiLight"/>
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="FontSize" Value="24"/>
                    </Style>

                    <Style x:Key="DateTimeStyle" TargetType="TextBlock">
                        <Setter Property="FontFamily" Value="Segoe UI"/>
                        <Setter Property="FontWeight" Value="SemiLight"/>
                        <Setter Property="Foreground" Value="White"/>
                        <Setter Property="FontSize" Value="16"/>
                    </Style>

                    <Converters:BoolToOpacityConverter x:Key="BoolToOpacityConverter"/>
                    <Converters:TimeToColorConverter x:Key="TimeToColorConverter"/>
                    <Converters:ResultToColorConverter x:Key="ResultToColorConverter"/>
                    <Converters:TaskToIconConverter x:Key="TaskToIconConverter"/>
                    <Converters:ResultToIconConverter x:Key="ResultToIconConverter"/>
                    <Converters:DataContextToDateRangeConverter x:Key="DataContextToDateRangeConverter"/>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="6"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="26"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="5"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="13"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10"/>
                </Grid.ColumnDefinitions>
                <!--<Image Grid.ColumnSpan="3" Grid.RowSpan="5" Source="../Assets/TaskTemplate/BgTask2.png" Stretch="None"></Image>-->
                <Rectangle Margin="0,2.5,0,0"   Grid.ColumnSpan="3" Grid.RowSpan="5"  Fill="{Binding Converter={StaticResource ResultToColorConverter}}" Opacity="{Binding IsConfirmed, Converter={StaticResource BoolToOpacityConverter}}"></Rectangle>
               
                <Image  Margin="0,2.5,0,0" Grid.ColumnSpan="3"  Source="{Binding Converter={StaticResource ResultToIconConverter}}" Grid.RowSpan="5" HorizontalAlignment="Left"></Image>
                <!--<Rectangle  Fill="#bdbdbd" Height="1" Grid.Row="1" Grid.Column="1" VerticalAlignment="Bottom" Margin="0,2,0,0" />-->
                <TextBlock Common:BindingService.FullText="{Binding Title}" Common:BindingService.HighlightedText="{Binding DataContext.Qtxt, ElementName=resultsPanel}" Common:BindingService.HighlightBrush="#3BB9FF" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1" Style="{StaticResource TxtProjectStyle}" VerticalAlignment="Bottom"  TextTrimming="WordEllipsis"/>
                <TextBlock Common:BindingService.FullText="{Binding Description}" Common:BindingService.HighlightedText="{Binding DataContext.Qtxt, ElementName=resultsPanel}" Common:BindingService.HighlightBrush="#3BB9FF" HorizontalAlignment="Left" Grid.Row="2" Grid.Column="1" VerticalAlignment="Top" Margin="0,0,0,5" Style="{StaticResource DateTimeStyle}" TextTrimming="WordEllipsis"/>
           
                <!--<Rectangle Grid.Row="2" Grid.RowSpan="2" Grid.ColumnSpan="3" Fill="White" Opacity="0.5"/>-->


            </Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    
    <Grid Style="{StaticResource LayoutRootStyle}">
        
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Popup
            x:Name="PopupMenu"
            Grid.ColumnSpan="3"
            Grid.RowSpan="7">
            <Grid
                x:Name="RootGridOfPopup"
                Background="Transparent"
                Height="{Binding ActualHeight, ElementName=PopupMenu}"
                Width="{Binding ActualWidth, ElementName=PopupMenu}">
                <Frame
                    x:Name="RootFrameOfPopup"
                    IsTabStop="False"
                    HorizontalAlignment="Right">
                </Frame>
            </Grid>
        </Popup>
        <Rectangle Fill="LightBlue" Grid.Column="0" Grid.Row="1"></Rectangle>
        <Grid x:Name="resultsPanel" Grid.Row="1" Grid.Column="1">
        <!--
            The body of the page in most view states uses an items controls to create multiple radio buttons
            for filtering above a horizontal scrolling grid of search results
        -->
            
            <Grid x:Name="typicalPanel">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <ItemsControl
                    x:Name="filtersItemsControl"
                    Canvas.ZIndex="1"
                    ItemsSource="{Binding Source={StaticResource filtersViewSource}}"
                    Visibility="{Binding ShowFilters, Converter={StaticResource BooleanToVisibilityConverter}}"
                    Margin="120,-3,120,30">

                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <RadioButton
                                GroupName="Filters"
                                IsChecked="{Binding Active, Mode=TwoWay}"
                                Checked="Filter_Checked"
                                Style="{StaticResource TextRadioButtonStyle}">
                                <TextBlock Text="{Binding Description}"  Margin="3,-7,3,10" Style="{StaticResource GroupHeaderTextStyle}" />
                            </RadioButton>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <Rectangle Grid.Row="1"  Grid.Column="1"  Stroke="#888888" StrokeThickness="1" StrokeDashArray="0.6,0,0.6" Fill="White"></Rectangle>

                <GridView
                    x:Name="resultsGridView"
                    AutomationProperties.AutomationId="ResultsGridView"
                    AutomationProperties.Name="Search Results"
                    TabIndex="1"
                    Grid.Row="1"
                    Grid.Column="1"
                    
                    Padding="30,30,110,46"
                    SelectionMode="None"
                    IsSwipeEnabled="false"
                    IsItemClickEnabled="True"
                    ItemContainerStyle="{StaticResource GridViewItemStyle_Task}"
                    ItemsSource="{Binding Source={StaticResource resultsViewSource}}"
                    ItemTemplate="{StaticResource TaskTemplate1}">
                    
                    
                </GridView>
            </Grid>

            <!--
                The body of the page when snapped uses a combo box to select a filter above a
                vertical scrolling list of search results
            -->
            <Grid x:Name="snappedPanel" Visibility="Collapsed">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <ComboBox
                    x:Name="filterComboBox"
                    ItemsSource="{Binding Source={StaticResource filtersViewSource}}"
                    Visibility="{Binding ShowFilters, Converter={StaticResource BooleanToVisibilityConverter}}"
                    Margin="20,0,20,20"
                    SelectionChanged="Filter_SelectionChanged"
                    HorizontalAlignment="Left"/>

                <ListView
                    x:Name="resultsListView"
                    AutomationProperties.AutomationId="ResultsListView"
                    AutomationProperties.Name="Search Results"
                    TabIndex="1"
                    Grid.Row="1"
                    Margin="10,0,0,0"
                    Padding="0,0,0,60"
                    SelectionMode="None"
                    IsSwipeEnabled="false"
                    IsItemClickEnabled="True"
                    ItemsSource="{Binding Source={StaticResource resultsViewSource}}"
                    ItemTemplate="{StaticResource StandardSmallIcon70ItemTemplate}">

                    <ListView.ItemContainerStyle>
                        <Style TargetType="Control">
                            <Setter Property="Height" Value="70"/>
                            <Setter Property="Margin" Value="0,0,18,8"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                </ListView>
            </Grid>
        </Grid>
        <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>

        <!-- Back button, page title and subtitles-->
        <Grid Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
           <TextBlock x:Name="pageTitle" Grid.Column="1" Text="Metro Calendar" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}"  />
            <TextBlock x:Name="resultText" Grid.Column="2" Text="" IsHitTestVisible="false" Style="{StaticResource PageSubheaderTextStyle}"/>
            <TextBlock x:Name="queryText" Grid.Column="3" Text="{Binding QueryText}" IsHitTestVisible="false" Style="{StaticResource PageSubheaderTextStyle}"/>
        </Grid>

        <TextBlock
            x:Name="noResultsTextBlock"
            Grid.Row="1"
            Grid.Column="1"
            Margin="120,50,0,0"
            Visibility="Collapsed"
            Style="{StaticResource SubheaderTextStyle}"
            Text="No results match your search." />

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="filtersItemsControl" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="100,-3,90,30"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="resultsGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="90,240,86,56"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="noResultsTextBlock" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="100,50,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped in addition to more extensive changes:
                    * The query text becomes the page header
                    * A different representation for filter selection and search results is used
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="queryText" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="resultText" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="typicalPanel" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="snappedPanel" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="noResultsTextBlock" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="20,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="noResultsTextBlock" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource BaselineTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>

            <VisualStateGroup x:Name = "ResultStates">
                <VisualState x:Name="ResultsFound" />
                <!-- When there are no results, the results panel is replaced with an informational TextBlock -->
                <VisualState x:Name="NoResultsFound">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="resultsPanel" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="noResultsTextBlock" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>						
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</Common:LayoutAwarePage>
